// pages/demo2/demo2.js
Page({
  data: {
      messages: [],
      inputValue: ''
  },
  onInput: function (e) {
      this.setData({
          inputValue: e.detail.value
      });
  },
  sendMessage: function () {
      const inputValue = this.data.inputValue;
      if (inputValue.trim() === '') {
          return;
      }
      const newMessages = this.data.messages.concat([{ content: inputValue, isMe: true }]);
      this.setData({
          messages: newMessages,
          inputValue: ''
      });
      setTimeout(() => {
          const reply = this.generateReply(inputValue);
          const updatedMessages = newMessages.concat([{ content: reply, isMe: false }]);
          this.setData({
              messages: updatedMessages
          });
      }, 1000);
  },
  generateReply: function (input) {
      const replies = [
          "您好，请问有什么可以帮您？",
          "请您详细描述一下问题哦。",
          "我这边会尽力为您解决。",
          "人工服务繁忙。"
      ];
      const randomIndex = Math.floor(Math.random() * replies.length);
      return replies[randomIndex];
  }
});